<?php
namespace app\index\controller;
use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;
class index extends Controller
{

    public function index()
    {
        $res = db('serviceuser')->order('id Desc')->paginate(10);
        $page = $res->render();
        //dump($res);exit;
        $this->assign('page', $page);
        $this->assign('list', $res);
        return $this->fetch();
    }

    public function cha()
    {
        //var_dump($_POST);
        if ($_POST['province']) {
            $data = array(
                'province' => $_POST['province'],
                'city' => $_POST['city'],
                'category' => $_POST['category']
            );
        }
//        if($_POST['city']){
//            $data = array(
//                'province' => $_POST['province'],
//                'city'     => $_POST['city']
//            );
//        }
//        if ($_POST['category']){
//            $data = array(
//               'category' => $_POST['category']
//            );
//        }
        if ($_POST['name']) {
            $data = array(
                'name' => $_POST['name']
            );
        }

        //$res = db('serviceuser')->where($data)->select();
        $res = db('serviceuser')->where($data)->order('id Desc')->paginate(10);
        //var_dump($res);exit;
        $page = $res->render();
        $this->assign('page', $page);
        $this->assign('list', $res);
        return $this->fetch();
    }

    //返回代理接口
    public function daili()
    {
        $res = db('chanpin')->column('id,title,img');

        return json_encode($res);
    }

    //代理总图
    public function dailiweb()
    {
        $res = db('user_meifeng')->order('id Desc')->paginate(10);
        $page = $res->render();
        $this->assign('page', $page);
        $this->assign('list', $res);
        return $this->fetch();
    }

    //代理详情
    public function dailiwebdetails()
    {
        $id['id'] = trim(input('id'));
        $res = db('user_meifeng')->where($id)->find();
        $this->assign('list', $res);
        //var_dump($res);exit;
        return $this->fetch();
    }

    //小程序请求数据用户接口
    public function zixun()
    {
        if (trim(input('pname'))) {
            $data = array(
                'pname' => trim(input('pname')),
                'name' => trim(input('name')),
                'tel' => trim(input('sheng')),
                'sheng' => trim(input('sheng')),
                'shi' => trim(input('shi')),
                'time' => time()
            );
            $res = db('user_zixun')->insert($data);
            if ($res) {
                $json = array(
                    'msg' => '提交成功',
                    'code' => 1
                );
            } else {
                $json = array(
                    'msg' => '提交失败',
                    'code' => 2
                );
            }
        } else {
            $json = array(
                'msg' => '不能为空',
                'code' => 0
            );
        }
        return json_encode($json);
    }

    //小程序接口装修价格计算
    public function jiage()
    {
        if (trim(input('cz_area'))) {
            $a = trim(input('cz_area'));
//                $b = trim(input(''));
            $c = trim(input('cz_1'));
            $d = trim(input('cz_2'));
            $m = 25;
            $e = $a;
            $g = $m * $e;
            $result = array(
                'msg' => '请求成功',
                'code' => 1,
                'cz_bj' => $g
            );
        } else {
            $result = array(
                'msg' => '不能为空',
                'code' => 0
            );
        }
        return json_encode($result);
    }

    public function kaifa()
    {
        return $this->fetch();
    }

    public function biao1()
    {


    }
}